#!/bin/bash
###############################################################################################
#   this script scan all Cateogry_xxxx_yyyymmddhhMMss.xml and only keeps the latest one according
# to the timestamp of file name, because one category file has several duplications, with 
# different timestamp
###############################################################################################

output_dir=$1;

cd $output_dir
fileArr=`ls Category_*.xml | sort`
file1='' # heading file
file2='' # tailing file
for file in $fileArr
do
    echo "[info] checking file $file..."
    file1=$file
    f1=`echo $file1 | cut -d'_' -f2`
    f2=`echo $file2 | cut -d'_' -f2`
    if [ $f1 == $f2 ] # not reach a new category
    then # keep the last one of previous category
        rm -fv $file2
    fi
    file2=$file1
done


